import { TableRowSelection } from "ant-design-vue/es/table/interface";
import type { StyleValue } from "vue";
import type { TableColumnType } from "ant-design-vue";

export type RowSelection = TableRowSelection;

export type Operatoin = {
	label: string;
	operation: string | number | symbol;
	rule?: string;
	onClick?: () => void;
	style?: StyleValue;
	color?: string;
	disabled?: boolean;
	permissionCode?: string;
	customRenderLabelNode?: <T = Dict>(this: Operatoin, column: T) => JSX.Element;
};

export type OnOperation = (type: string, column: Column) => void;

export interface Pageation {
  current: number;
  size: number;
  asc?: string;
  desc: string;
}

export const TableContextKey = "TableContextKey";

export interface TableContext {
  refetch<T = any>(nextFetchPayload?: T): void;
  fetchLoading(loading?: boolean): boolean;
  clear(): void;
  syncUpdateDataSource<T = any>(callback: (dataSource: T[]) => T[]): void;
}


export type ColumnTag = {
  label: string;
  type?: string;
  color?: string;
  style: StyleValue;
};


export type ColumnTagList = boolean | ColumnTag[] | ColumnTag;
export type OperationRender<T = Operatoin> = (row: Readonly<RowInputForTable>) => T | null;
export type OperRenderCol = Operatoin[];
export type TableOperationInput = OperRenderCol | OperationRender<Operatoin[]>;
export type Column = (
  TableColumnType &
  {
    operations?: TableOperationInput;
    shouldTagText?: ColumnTagList;
  } &
  {
    ellipsis?: boolean | {
      showTitle?: boolean;
      size?: number;
      not?: boolean;
    }
  }
);

export type AutoTableColumns = Column[];

